package com.ms.hotevent.interceptor;

import com.ms.hotevent.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class UserInteceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("进入UserInteceptor.."+request.getRequestURI());
        User user = (User) request.getSession().getAttribute("user");
        if(user == null){
            throw new RuntimeException("用户未登录");
        }
        return true;
    }
}
